<template>
    <div v-if="readyShow">
        <el-table :data="showCreditorList" style="width: 100%;">
            <el-table-column
                    prop="creditorNo"
                    label="债权人编号"
                    width="">
            </el-table-column>
            <el-table-column
                    prop="name"
                    width="110px"
                    label="债权人姓名"
                    align="left">
            </el-table-column>
            <!--<el-table-column
            prop="stateStr"
            width="90px"
            label="资格审核状态"
            align="left">
            </el-table-column>-->
            <el-table-column
                    align="right"
                    label="操作"
                    width="100px">
                <template slot-scope="scope">
                    <el-button @click="toMain(scope.row)" type="text" size="medium"> 查看</el-button>
                    <br/>
                    <el-button @click="toDelete(scope.$index)" type="text"
                               size="medium">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-dialog
                title="是否确定删除"
                :visible.sync="centerDialogVisible"
                width="80%"
                center>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteAffirm">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
    /* import CreditList from './credit-list.vue'*/
    import util from 'assets/js/util.js'
    import ElFormItem from "../../../../../node_modules/element-ui/packages/form/src/form-item.vue";

    export default {
        data() {
            return {
                showCreditorList: [],
                // activeNames: [],
                centerDialogVisible: false,
                readyShow: true,
                index: -1,
            }
        },
        props: [
            'caseId',
            'data'
        ],
        mounted() {
            const _self = this;
            this.data.forEach(_creditor => _self.showCreditorList.push({
                orgName: _creditor.orgName,
                id: _creditor.id,
                stateStr: _creditor.stateStr,
                name: _creditor.name,
                creditorNo: _creditor.creditorNo || '',
            }));

        },
        methods: {
            toMain: function (row) {
                sessionStorage.setItem("name", row.name);
                window.location.href = '../main/main.html?' + 'caseId=' + this.caseId + '&creditorId=' + row.id;
            },
            toDelete: function (index) {
                this.index = index;
                this.centerDialogVisible = true;
            },
            deleteAffirm: function (index) {
                const _self = this;
                this.centerDialogVisible = false;
                this.id = _self.showCreditorList[this.index].id;

                util.ajax({
                    url: '/index/removeCreditor',
                    params: {creditorId: this.id},
                    success: function (data) {
                        if (data.status == 200) {
                            alert('删除成功!')
                            location.reload()

                        } else {
                            alert(data.error);
                        }
                    },
                    error: function (error) {
                        alert(error);
                    },
                })
            },
        },

        components: {
            ElFormItem,
            /*CreditList*/
        }
    }
</script>

<style>

</style>
